<template>
  <div class="news-container">
    <div class="news-list-container">
      <h2 class="news-header">最新新闻</h2>
      <ul class="news-list">
        <li v-for="news in newsList" :key="news.id" class="news-item">
          <!-- 第一种写法 -->
          <!-- <RouterLink
            :to="`/news/detail?id=${news.id}&title=${news.title}&content=${news.content}`"
            class="news-link"
            active-class="active-news"
          > -->

          <!-- 第二种写法 -->
          <!-- <RouterLink
            :to="{
              name: 'newsDetail',
              query: {
                id: news.id,
                title: news.title,
                content: news.content,
              },
            }"
            class="news-link"
            active-class="active-news"
          > -->

          <!-- 第三种：params参数 -->
          <RouterLink
            :to="{
              name: 'newsDetail',
              params: {
                id: news.id,
                title: news.title,
                content: news.content,
              },
            }"
            class="news-link"
            active-class="active-news"
          >
            <span class="news-title">{{ news.title }}</span>
            <span class="news-marker">→</span>
          </RouterLink>
        </li>
      </ul>
    </div>

    <div class="news-content">
      <router-view></router-view>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from "vue";

const newsList = reactive([
  {
    id: "001",
    title: "如何实现一夜暴富",
    content: "如何实现一夜暴富的新闻内容是：学会炒股",
  },
  {
    id: "002",
    title: "震惊全世界的大事件",
    content: "震惊全世界的大事件新闻内容是：明天全国放假",
  },
  {
    id: "003",
    title: "好消息，好消息！",
    content: "好消息，全场商城1折处理",
  },
]);
</script>

<style scoped>
/* 基础布局 */
.news-container {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  gap: 2rem;
}

.news-list-container {
  flex: 0 0 350px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  padding: 1.5rem;
  height: fit-content;
}

.news-content {
  flex: 1;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  padding: 2rem;
}

/* 新闻列表样式 */
.news-header {
  font-size: 1.5rem;
  font-weight: 600;
  color: #2d3748;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #e2e8f0;
}

.news-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.news-item {
  margin-bottom: 0.75rem;
  transition: transform 0.2s ease;
}

.news-item:hover {
  transform: translateX(5px);
}

.news-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-decoration: none;
  color: #4a5568;
  padding: 1rem;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.news-link:hover {
  background: #f7fafc;
  color: #2b6cb0;
}

.active-news {
  background: #ebf8ff;
  color: #2b6cb0;
  font-weight: 500;
}

.news-title {
  flex: 1;
  font-size: 1.05rem;
}

.news-marker {
  opacity: 0;
  transition: all 0.2s ease;
  color: #4299e1;
  font-weight: bold;
}

.news-link:hover .news-marker,
.active-news .news-marker {
  opacity: 1;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .news-container {
    flex-direction: column;
    padding: 1rem;
  }

  .news-list-container {
    flex: 1;
    width: 100%;
  }

  .news-content {
    min-height: 400px;
  }
}

/* 内容区域过渡动画 */
.news-content {
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>
